package com.example.toolbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class CityActionDetailActivity extends Activity {
	private ListView listView;
	private MAdapter mAdapter;
	private JSONArray jsonArray;
	private ImageView touxiang;
	private TextView nickname;
	private TextView address;
	private TextView time;
	private TextView tel;
	private TextView content;
	private View   hearderView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.city_wide_entry_listview);
		listView = (ListView) findViewById(android.R.id.list);
		hearderView = LayoutInflater.from(CityActionDetailActivity.this).inflate(R.layout.action_datails, null);
		String s= "{   \"data\": {     \"activityParticipateIns\": [       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-11 11:43:19\",         \"id\": 1,         \"lastUpdate\": \"2015-08-11 11:43:20\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": \"LL\",           \"avatar\": \"assets/images/avatar/1_avatar.png\",           \"dateline\": \"2015-08-06 17:23:06\",           \"email\": \"\",           \"gender\": \"BOY\",           \"id\": 1,           \"lastUpdate\": \"2015-08-19 13:16:52\",           \"latitude\": \"22.1\",           \"longitude\": \"11.1\",           \"nickName\": \"夏悸\",           \"userName\": \"郭华\"         }       },       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-14 08:55:15\",         \"id\": 2,         \"lastUpdate\": \"2015-08-14 08:55:15\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": \"HT\",           \"avatar\": \"assets/images/avatar/2_avatar.jpg\",           \"dateline\": \"2015-08-11 09:51:24\",           \"email\": \"lifenote@21cn.com\",           \"gender\": \"BOY\",           \"id\": 2,           \"lastUpdate\": \"2015-08-14 09:00:54\",           \"latitude\": \"22.1\",           \"longitude\": \"11.1\",           \"nickName\": \"赞赞\",           \"userName\": \"李赞红\"         }       },       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-14 09:47:31\",         \"id\": 3,         \"lastUpdate\": \"2015-08-14 09:47:31\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": \"TY\",           \"avatar\": \"assets/images/avatar/4_avatar.png\",           \"dateline\": \"2015-08-14 09:31:03\",           \"email\": \"363798478@qq.com\",           \"gender\": \"GIRL\",           \"id\": 4,           \"lastUpdate\": \"2015-08-14 10:15:18\",           \"latitude\": \"22.1\",           \"longitude\": \"11.1\",           \"nickName\": \"夏悸\",           \"userName\": \"谢芬兰\"         }       },       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-14 10:12:04\",         \"id\": 5,         \"lastUpdate\": \"2015-08-14 10:12:04\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": null,           \"avatar\": \"\",           \"dateline\": \"2015-08-14 10:10:42\",           \"email\": \"hunangongdahou@163.com\",           \"gender\": null,           \"id\": 16,           \"lastUpdate\": \"2015-08-17 14:42:59\",           \"latitude\": \"22.1\",           \"longitude\": \"11.1\",           \"nickName\": \"hou\",           \"userName\": \"hou\"         }       },       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-14 13:09:24\",         \"id\": 6,         \"lastUpdate\": \"2015-08-14 13:09:26\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": \"LL\",           \"avatar\": \"assets/images/avatar/48_avatar.gif\",           \"dateline\": \"2015-08-14 13:08:00\",           \"email\": \"lisi@21cn.com\",           \"gender\": \"BOY\",           \"id\": 48,           \"lastUpdate\": \"2015-08-16 22:16:01\",           \"latitude\": \"22.1\",           \"longitude\": \"11.1\",           \"nickName\": \"夏悸\",           \"userName\": \"李四\"         }       },       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-17 10:13:18\",         \"id\": 7,         \"lastUpdate\": \"2015-08-17 10:13:18\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": \"LL\",           \"avatar\": \"\",           \"dateline\": \"2015-08-17 09:10:10\",           \"email\": \"\",           \"gender\": \"BOY\",           \"id\": 65,           \"lastUpdate\": \"2015-08-17 09:57:38\",           \"latitude\": \"22.1\",           \"longitude\": \"11.1\",           \"nickName\": \"夏悸\",           \"userName\": \"张三\"         }       },       {         \"content\": \"我要参与\",         \"dateline\": \"2015-08-19 17:05:39\",         \"id\": 8,         \"lastUpdate\": \"2015-08-19 17:05:39\",         \"telephone\": \"18676037292\",         \"user\": {           \"area\": null,           \"avatar\": \"\",           \"dateline\": \"2015-08-14 11:28:21\",           \"email\": \"\",           \"gender\": \"UNKONW\",           \"id\": 38,           \"lastUpdate\": \"2015-08-14 11:28:21\",           \"latitude\": \"\",           \"longitude\": \"\",           \"nickName\": \"\",           \"userName\": \"史振宇\"         }       }     ],     \"address\": \"王府井\",     \"area\": \"YX\",     \"dateline\": \"2015-08-11 11:37:19\",     \"description\": \"采荷挖藕\",     \"endLine\": \"2015-08-20 00:00:00\",     \"id\": 1,     \"images\": \"assets/images/fact/2015/08/abd2b5a994426f83d2f556163a3fb4c8.jpg,assets/images/fact/2015/08/38ac49eea41ced01ef32b80a2bf8f7d8.jpg\",     \"lastUpdate\": \"2015-08-11 11:37:20\",     \"peoples\": 20,     \"startLine\": \"2015-08-15 00:00:00\",     \"title\": \"赏荷大会\",     \"user\": {       \"area\": \"LL\",       \"avatar\": \"assets/images/avatar/1_avatar.png\",       \"dateline\": \"2015-08-06 17:23:06\",       \"email\": \"\",       \"gender\": \"BOY\",       \"id\": 1,       \"lastUpdate\": \"2015-08-19 13:16:52\",       \"latitude\": \"22.1\",       \"longitude\": \"11.1\",       \"nickName\": \"夏悸\",       \"userName\": \"郭华\"     }   },   \"message\": \"\",   \"success\": true }";
		jsonArray = JSON.parseObject(s).getJSONObject("data").getJSONArray("activityParticipateIns");
		mAdapter = new MAdapter();
		listView.addHeaderView(hearderView);
		listView.setAdapter(mAdapter);
	}
	class MAdapter extends BaseAdapter {
		@Override
		public int getCount() {
			return jsonArray.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final ViewHoder viewHolder;
			if (convertView == null) {
				convertView = LayoutInflater
						.from(CityActionDetailActivity.this).inflate(
								R.layout.action_entry_item, null);
				viewHolder = new ViewHoder();
				viewHolder.touxiang = (ImageView) convertView
						.findViewById(R.id.city_touxiang);
				viewHolder.nickname = (TextView) convertView
						.findViewById(R.id.city_enty_user_name);
				viewHolder.address = (TextView) convertView
						.findViewById(R.id.city_dizhi);
				viewHolder.time = (TextView) convertView
						.findViewById(R.id.city_pinglun_time);
				viewHolder.content = (TextView) convertView
						.findViewById(R.id.city_entry_content);
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHoder) convertView.getTag();
			}
			
			JSONObject obj = jsonArray.getJSONObject(position);
//			Uri uri=Uri.parse(("http://tr.zzapi.gson.cn/"+obj.getJSONObject("user").getString("avatar")));
//			viewHolder.touxiang.setImageURI(uri);
			viewHolder.nickname.setText((obj.getJSONObject("user").getString("nickName")));
//			viewHolder.address.setText(obj.getString(""))
			viewHolder.time.setText(obj.getString("dateline"));
			viewHolder.content.setText(obj.getString("content"));
			return convertView;
		}

	}

	class ViewHoder {
		JSONArray jsonArray;
		ImageView touxiang;
		TextView nickname;
		TextView address;
		TextView time;
		TextView content;
	}
}
